local tuisui = fk.CreateSkill {
  name = "th_tuisui",
}

tuisui:addEffect("viewas", {
  name = "th_tuisui",
  mute_card = false,
  prompt = function(self)
    if self.interaction and self.interaction.data then
      return "#th_tuisui-viewas:::" .. self.interaction.data
    end
    return "#th_tuisui-viewas0"
  end,
  pattern = ".|.|.|.|.|basic",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local names = player:getViewAsCardNames("th_tuisui", all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player,cards)
    if not self.interaction then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = tuisui.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function(p) return p:getMark("_th_tuisui-turn") == 0 and player:canPindian(p) end)
    local tos = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#th_tuisui-invoke:::" .. use.card.trueName,
      skill_name = tuisui.name,
      cancelable = false
    })
    if #tos < 1 then return "" end
    local target = tos[1]
    room:addPlayerMark(target, "_th_tuisui-turn", 1)
    local pindian = player:pindian({target}, tuisui.name)
    if pindian.results[target].winner == player then
      return
    end
    player:turnOver()
    room:invalidateSkill(player, tuisui.name, "-turn", tuisui.name)
    return ""
  end,
  enabled_at_play = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function(p) return p:getMark("_th_tuisui-turn") == 0 and player:canPindian(p) end)
  end,
  enabled_at_response = function(self, player, response)
    return table.find(Fk:currentRoom().alive_players, function(p) return p:getMark("_th_tuisui-turn") == 0 and player:canPindian(p) end)
  end,
  enabled_at_nullification = Util.FalseFunc
})

Fk:loadTranslationTable{
  ["th_tuisui"] = "推祟",
  [":th_tuisui"] = "当你需要使用或打出基本牌时，你可以与本回合未以此法选择过的角色拼点：若你赢，视为使用或打出你需要的牌；若你没赢，你翻面，然后本回合此技能失效。",

  ["#th_tuisui-viewas"] = "推祟：你可以与一名角色拼点：若你赢，视为使用或打出 %arg ；若你没赢，你翻面",
  ["#th_tuisui-viewas0"] = "推祟：你可以与一名角色拼点：若你赢，视为使用或打出基本牌；若你没赢，你翻面",
  ["#th_tuisui-invoke"] = "推祟：你须与一名角色拼点：若你赢，视为使用或打出 %arg ；若你没赢，你翻面",
}

return tuisui